package com.hzhk.happyrent.ui.adapter.card;

import android.content.Context;
import android.graphics.drawable.BitmapDrawable;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.hzhk.happyrent.App;
import com.hzhk.happyrent.R;
import com.hzhk.happyrent.bean.card.BankCardHotModel;
import com.hzhk.happyrent.bean.card.CardHotModel;
import com.hzhk.happyrent.ui.adapter.BaseAdapter;
import com.hzhk.happyrent.utils.CreateBitmapImage;
import com.hzhk.happyrent.utils.ListUtils;
import com.hzhk.happyrent.utils.glide.ShowImageUtils;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by soft_zzc on 2017/11/26.
 * <p>
 * 用于热门银行里热门卡片的adapter
 */

public class BankCardHotAdapter extends BaseAdapter<BankCardHotModel.DataBean.CardsBean> {


    private Logger log = LoggerFactory.getLogger(this.getClass().getName());
    private CardHotModel cardHotModel;

    public BankCardHotAdapter(Context context) {
        super(context);
        log.debug("jump into CardHotAdapter");
    }


    @Override
    public View getView(int position, View convertView, ViewGroup arg2) {
        ViewHolder viewHolder;
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.item_card_bank, null);
            viewHolder = new ViewHolder(convertView, position,mContext);
            viewHolder.setData(mList.get(position));
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
            viewHolder.setData(mList.get(position));
        }
        return convertView;
    }

    static class ViewHolder {

        @BindView(R.id.card_top_pic)
        ImageView cardTopPic;
        @BindView(R.id.Re_card_hot)
        LinearLayout ReCardHot;
        @BindView(R.id.card_hot_text1)
        TextView cardHotText1;
        @BindView(R.id.card_hot_text2)
        TextView cardHotText2;
        @BindView(R.id.card_hot_text3)
        TextView cardHotText3;
        @BindView(R.id.li_card_hot)
        LinearLayout liCardHot;
        @BindView(R.id.card_hot_no)
        TextView cardHotNo;
        @BindView(R.id.Re_card_hot_jump_into)
        LinearLayout ReCardHotJumpInto;

        int position;
        private Context context;
        ViewHolder(View view, int position,Context context) {
            this.position = position;
            this.context = context;
            ButterKnife.bind(this, view);
        }

        public void setData(final BankCardHotModel.DataBean.CardsBean cardsBean) {
            ShowImageUtils.showImageView(App.getContext(),cardTopPic,cardsBean.getImage());
            cardHotText1.setText(cardsBean.getTitle());
            if(!ListUtils.isEmpty(cardsBean.getSelling_point())){
                String message = "";
                for (String s : cardsBean.getSelling_point()) {
                    message=message+s+"，";
                }
                cardHotText2.setText(message.substring(0,message.length()-1));
            }
            if(!ListUtils.isEmpty(cardsBean.getTags())){
                String message = "";
                for (String s : cardsBean.getTags()) {
                    message=message+s+"，";
                }
                cardHotText3.setText(message.substring(0,message.length()-1));
            }
            BitmapDrawable bd = new BitmapDrawable(CreateBitmapImage
                    .getInstance().getBitmap(cardHotNo, "#FA7D0F"));
            cardHotNo.setBackgroundDrawable(bd);

          /*  ReCardHotJumpInto.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {



                }
            });*/
        }
    }
}
